package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.utils.DateUtils;
import com.common.utils.base.UuidUtil;
import com.entity.Product;
import com.repository.ProductDao;
import com.service.base.BaseServiceImp;

@Service("ProductService")
public class ProductServiceImpl extends BaseServiceImp<Product> implements ProductService{

	@Autowired
	private ProductDao productDao;
	
	@Override
	@Transactional
	public String insert(Product o) {
		o.setId(UuidUtil.get32UUID());
		o.setReviewTimes(0);
		o.setPublishTime(DateUtils.getDate("yyyy/MM/dd HH:mm:ss"));
		productDao.insert(o);
		return o.getId();
	}

	@Override
	@Transactional
	public void updateState(Product product) {
		productDao.updateState(product);
	}

	@Override
	@Transactional
	public void updateReject(Product product) {
		if(product.getReviewDate() == null || product.getReviewDate().equals("")){
			product.setReviewDate(DateUtils.getDate("yyyy/MM/dd HH:mm:ss"));
		}else{
			product.setReviewDate(product.getReviewDate() + ";" + DateUtils.getDate("yyyy/MM/dd HH:mm:ss"));
		}
		productDao.updateReject(product);
	}	
	
}
